﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;


public class FaXianPanel : EventManager {

    public Button Club,JX;
    public GameObject Clubs, Going;
    public Transform panel;
    public GameObject view;
    public GameObject Item;
    private void Awake()
    {
        Item.GetComponent<RoomPanel>().TypeID = 0;
        Club.onClick.AddListener(ShowClub);
        JX.onClick.AddListener(ShowGoing);
        BindingSource[1].GetComponent<Button>().onClick.AddListener(delegate
        {
            MyClub();
            MessageManager.GetInstance().SendMsg768();
            Des();
        });
        BindingSource[2].GetComponent<Button>().onClick.AddListener(delegate
        {
            FirstPanel();
            Des();
        });
        BindingSource[3].GetComponent<Button>().onClick.AddListener(delegate
        {
            ZhanJiBtnClick();
        });
        BindingSource[4].GetComponent<Button>().onClick.AddListener(delegate
        {
            GetMe();
            Des();
        });
        RoomMsg();
    }
    /// <summary>
    /// 删除本面板
    /// </summary>
    void Des()
    {
        Destroy(this.gameObject);
    }
    void ShowClub() {
        DesChrid();
        Clubs.gameObject.SetActive(true);
        Going .gameObject.SetActive(false);
        Item.GetComponent<RoomPanel>().TypeID = 1;
        clubRoomMsg();
    }
    void ShowGoing()
    {
        DesChrid();
        Clubs.gameObject.SetActive(false);
        Going.gameObject.SetActive(true);
        Item.GetComponent<RoomPanel>().TypeID = 0;
        RoomMsg();
    }
    void DesChrid() {
        int sum = panel.GetChildCount();
        if (sum>0)
        {
            for (int i = 0; i < sum; i++)
            {
                Destroy(panel.GetChild(i).gameObject);
            }
        }
    }
    void FirstPanel() {
        UIManager.ChangeUI(UIManager.PageState.GameHallPage, (GameObject obj) =>
        {
            obj.GetComponent<GameHallPanel>().InformationSetting();
        });
    }
    void ZhanJiBtnClick()
    {
        MessageManager.GetInstance().Send7131(0, GameData.GetInstance().userID);
    }
    void MyClub() {
        UIManager.ChangeUI(UIManager.PageState.Club, (GameObject obj) =>
        {
            obj.GetComponent<MyClubbPanel>().InformationSetting();
        });
    }
    void GetMe()
    {
        UIManager.ChangeUI(UIManager.PageState.GetMe, (GameObject obj) =>
        {
            obj.GetComponent<GetMePanel>().InformationSetting();
        });
    }
    public override void InformationSetting()
    {
        Open();
    }
    void RoomMsg() {
        if (SaveDate.GetInstance().GetRoomRet.roomMsg!=null)
        {
            view.transform.GetComponentsInChildren<OneP.InfinityScrollView.InfinityScrollView>()[0].Setup(SaveDate.GetInstance().GetRoomRet.roomMsg.Count);
        }
    }
    void clubRoomMsg() {
        if (SaveDate.GetInstance().GetRoomRet.clubRoomMsg != null)
        {
            view.transform.GetComponentsInChildren<OneP.InfinityScrollView.InfinityScrollView>()[0].Setup(SaveDate.GetInstance().GetRoomRet.clubRoomMsg.Count);
        }
    }
}
